package edu.gdkm.sql.dao;

import edu.gdkm.sql.pojo.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {

    @Select("SELECT * FROM vueshop_category")
    List<Category> findAll();

    @Select("SELECT * FROM vueshop_category WHERE id = #{id}")
    @Results(id = "vueshopCategoryResultMap", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "picture", column = "picture"),
            @Result(property = "pid", column = "pid")
    })
    Category findById(@Param("id") Integer id);

    @Insert("INSERT INTO vueshop_category(name, picture, pid) VALUES(#{name}, #{picture}, #{pid})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Category category);

    @Update("UPDATE vueshop_category SET name=#{name}, picture=#{picture}, pid=#{pid} WHERE id=#{id}")
    void update(Category category);

    @Delete("DELETE FROM vueshop_category WHERE id=#{id}")
    void delete(@Param("id") Integer id);
}
